﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using cn.edu.jnmc.pb;

public partial class Mark : System.Web.UI.Page
{
    private const int ARTICLE_NUM = 6;
    //private string[] articleTitles;
    private OleDbConnection conn;
    protected void Page_Load(object sender, EventArgs e)
    {
        conn = DatabaseService.DBopen();
        if (!IsPostBack)
        {
        }
        if (!string.IsNullOrEmpty(Request.Form["mark"]))
        {
            saveScore();
        }
    }
    private void saveScore()
    {
        string[] studentScores = new string[6]; //= Request.Form["stuscore"].Split(',');
        string[] teacherScores = new string[6]; //= Request.Form["tchscore"].Split(',');
        
        string insertSql = "insert into article_score (article_id, name, student_score, teacher_score) values({0},'{1}',{2},{3});";

        bool founderr = false;
        string msg = ""; 
        double fen;
        for (int i = 0; i < ARTICLE_NUM; i++)
        {
            string studentScore = Request.Form["stuscore" + (i + 1)];
            string teacherScore = Request.Form["tchscore" + (i + 1)]; ;
            if (!double.TryParse(studentScore, out fen) || !double.TryParse(teacherScore, out fen))
            {
                founderr = true; break;
            }
            studentScores[i] = studentScore;
            teacherScores[i] = teacherScore;
        }
        if (founderr)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "ss", "alert('数据填写出错，请完整填写后重新提交！');", true);
            return;
        }
        for (int i = 0; i < ARTICLE_NUM; i++)
        {
            DatabaseService.executeCommendSQL(string.Format(insertSql,(i+1),"",double.Parse(studentScores[i]),double.Parse(teacherScores[i])), conn);
        }
        Response.Redirect("Default.aspx");
    }

    private void initList()
    {
        //articleTitles = new string[ARTICLE_NUM]
        //{
        //    "GSZ 英语翻译竞赛参评译文",
        //    "GZG 英语翻译竞赛参评译文",
        //    "LLM 英语翻译竞赛参评译文",
        //    "LXM 英语翻译竞赛参评译文",
        //    "LYF 英语翻译竞赛参评译文",
        //    "XS 英语翻译竞赛参评译文"
        //};       
    }
}